import scala.util.Random
class MusicPlayer{
  var musicList:List[String]=List()
  var musicName:String=""
  var playing:String=""
  // The way music is played
  var kinds=Array("criculate","order","random")

  def addMusic(name:String):Unit={
    musicList=musicList:+name
  }

  def delMusic(name:String):Unit={
    musicList=musicList.filter(_!=name)
  }

  def playMusic():Unit={
    if (musicName==""){
      musicName=musicList.head
    }
    println(musicName)
  }

  def next_play():Unit={
    if (playing==kinds(0)){
      criculate_play()
    }else if(playing==kinds(1)){
      order_play()
    }else{
      random_play()
    }
    println(musicName)
  }

  def criculate_play():Unit={
    if (musicList.exists(s=> s=="musicName")){
      musicName=musicName
    }else{
      musicList=musicList:+musicName
      musicName=musicName
    }
  }

  def order_play():Unit={
    val index=musicList.indexOf(musicName)
    if (index==musicList.length){
      musicName=musicList(0)
    }else{
      musicName=musicList(index+1)
    }
  }

  def random_play():Unit={ 
    val random=new Random
    musicName=musicList(random.nextInt(musicList.length))
  }

}
